package com.ddwl.shop.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.shop.ShopStaffBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.shop.ShopStaffVo;
import com.ddwl.schema.vo.shop.ShopVo;
import com.ddwl.shop.service.ShopStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 门店员工接口
 * @author wenbin
 */
@Api(tags = "门店员工接口")
@RequestMapping("/shopStaff")
@RestController
public class ShopStaffController extends BaseController {

    @Resource
    private ShopStaffService shopStaffService;

    @PostMapping("/createStaff")
    @ApiOperation("注册员工")
    @Auth(required = false)
    public RestVo createStaff(@RequestBody ShopStaffBo bo) {
        shopStaffService.create(bo,getAuthMap().get("pk"));
        return RestVo.ok();
    }

    @GetMapping("/shareKey/{shareKey}")
    @ApiOperation("创建分享key")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE,BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<String> createShareKey(@PathVariable("shareKey")String shareKey) {
        return RestVo.ok( shopStaffService.createShareKey(getUserId(),shareKey));
    }

    @Deprecated
    @PostMapping("/checkKey")
    @ApiOperation("校验分享key")
    @Auth(required = false)
    public RestVo checkShareKey(@RequestParam String shareKey) {
        return RestVo.ok( shopStaffService.checkShareKey(shareKey));
    }


    @DeleteMapping("/deleteStaff/{id}")
    @ApiOperation("删除员工")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE,BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo deleteStaff(@PathVariable("id") String id) {
        shopStaffService.delete(id);
        return RestVo.ok();
    }

    @PostMapping("/updateStaff")
    @ApiOperation("修改员工")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<ShopVo> updateStaff(@RequestBody ShopStaffBo bo) {
        shopStaffService.update(bo);
        return RestVo.ok();
    }

    @GetMapping("/shopStaffList")
    @ApiOperation("员工列表")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE,BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<List<ShopStaffVo>> shopStaffList() {
        List<ShopStaffVo> list = shopStaffService.list(getUserId());
        return RestVo.ok(list);
    }

    @GetMapping("/shopList")
    @ApiOperation("门店列表")
    @Auth
    public RestVo<List<ShopStaffVo>> shopList() {
        return RestVo.ok(shopStaffService.getShopList(getUserId()));
    }

    @GetMapping("/shopListForApi")
    @ApiOperation("门店列表")
    @Auth(product = {BaseEnum.ProductEnum.API})
    public RestVo<List<ShopStaffVo>> shopListForApi(@RequestParam String userId) {
        List<ShopStaffVo> list = shopStaffService.getShopList(userId);
        return RestVo.ok(list);
    }

}
